// Convert args from object notation to an array of "key=value" pairs,
// performing any escaping necessary for use in URL.
var argsArray = [];
for (var key in aArgs) {
argsArray.push(encodeURIComponent(key) + "="
+ encodeURIComponent(aArgs[key]));
}
// Build the complete API command: host, API method, and args.
var url = this._url + aAPIMethod;
if (argsArray.length) {
url = url + "?" +argsArray.join("&");
}
// Build an XMLHTTPRequest for sending the API call.
var request = CC["@mozilla.org/xmlextras/xmlhttprequest;1"]
.createInstance(CI.nsIXMLHttpRequest);
var onReadyStateFunc = function deliciousAPI_call_onReadyStateFunc(eEvt) {
if (request.readyState == 4) {
if (request.status >= 200 && request.status < 300) {
// Scrub input and create an nsIDOMDocument.
var text = request.responseText.replace(/[\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0B\x0C\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F]/g, "");
if (!text) {
text = "<?xml version='1.0' standalone='yes'?>";
}
var xml = CC["@mozilla.org/xmlextras/domparser;1"]
.createInstance(CI.nsIDOMParser)
.parseFromString(text, "text/xml");
aAPIListener.onSuccess(xml);
} else {
var error = CC["@flock.com/error;1"].createInstance(CI.flockIError);